﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Persisted;
using THE_WIND_RISES.Common.Dtos;
using WorkflowCore.Models;
using WorkflowCore.Service.Dto.Fundamentals;
namespace Production_Get.API.Application.Commands.WorkCenter_W
{
    public class WorkflowInstanceShowHandler : IRequestHandler<WorkflowInstanceShowCommand, Result>
    {
        private readonly IBaseRepositoryGet<PersistedWorkflowInstance> WorkflowInstanceRepository;

        public WorkflowInstanceShowHandler(IBaseRepositoryGet<PersistedWorkflowInstance> workflowInstanceRepository)
        {
            WorkflowInstanceRepository = workflowInstanceRepository;
        }

        public async Task<Result> Handle(WorkflowInstanceShowCommand request, CancellationToken cancellationToken)
        {
            var result = new THE_WIND_RISES.Common.Dtos.Result() { Code = (int)CommonErrorCodes.Search };
            try
            {
                var sql = $"select * from WorkflowInstance where FormFields = '{request.workCenterNum}' and Title = '{request.Title}'";
                var list = from a in WorkflowInstanceRepository.GetAll(sql)
                           select new
                           {
                               a.WorkflowInstanceId
                           };
                if (list != null)
                {
                    result.Data = list;
                    result.Msg = "查询成功";
                    result.Code = (int)CommonErrorCodes.Success;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return result;
        }
    }
}
